<template>
  <div>
    <van-nav-bar
         left-arrow
        class="app-nav-bar"
        title="卫生检查修改"
        @click-left="$router.back()"
      />
      <van-form @submit="onSubmit">
          <van-field
             readonly
                v-model="currentDate"
                right-icon="arrow"
                label="检查日期"
                 @click="showPopup"
            />
            <van-popup v-model="dateShare" position="bottom" :style="{ height: '45%' }">
                <van-datetime-picker
                    type="date"
                    title="选择年月日"
                    :min-date="minDate"
                    :max-date="maxDate"
                    @confirm="confirm"
                    @cancel="dateShare = false"
                    :formatter="formatter"
                />
            </van-popup>
           <van-field
                readonly label="宿舍" :value="tableData.dorAddress"/>
            <!-- <van-field
                readonly
                v-model="classContent"
                right-icon="arrow"
                label="卫生项"
                placeholder="请选择卫生项"
                @click="classListShare=true"
            /> -->
             <van-cell title="卫生项">
                 <template #default>
                      <el-select v-model="classContent" multiple placeholder="请选择">
                        <el-option
                        v-for="item in classList"
                        :key="item.id"
                        :label="item.name"
                        :value="item.id">
                        </el-option>
                    </el-select>
                 </template>
             </van-cell>
            <!-- <van-action-sheet 
                v-model="classListShare"
                title="请选择"
                :actions="classList" 
                @select="onSelect" 
            /> -->
             <van-field
                v-model="form.leaveReason"
                label="描述信息"
                :rules="[{ required: true, message: '请填写描述信息' }]"
            />
            <!-- 提交 -->
            <div style="margin:16px">
                <van-button round block type="info" native-type="submit">提交</van-button>
            </div>
        </van-form>
  </div>
</template>

<script>
import {Notify} from 'vant'
export default {
    name:'HygieneEdit',
    data(){
        return{
            minDate: new Date(2000, 0, 1),
            maxDate: new Date(2021, 10, 1),
            currentDate:'',
           form:{
               studentNo: '',
                classId: '',
                className: "",
                studentName: '',
                leaveType: '',
                leaveReason: ''
           },
           tableData:[],
            status:[],
            statusListShare:false,
            statusContent:"",
            classList:[],
            classListShare:false,
            classContent:[],
             dateShare:false,
             yyyy:null,
             MM:null,
             dd:null
        }
    },
     methods:{
         showPopup() {
            this.dateShare = true;
        },
         confirm(){
            this.currentDate=`${this.yyyy}-${this.MM}-${this.dd}`
            this.dateShare=false
         },
        async onSubmit(){
            var {data:res} = await this.$axios({
                url:this.$location.editHygiene,
                method:'post',
                data:{
                    bdormitoryId: 10,
                    buildingNo: null,
                    checkDate: this.currentDate,
                    createBy: this.tableData.createBy,
                    createById: null,
                    createTime: this.tableData.createTime,
                    deductIds: this.classContent,
                    deductOptions: this.tableData.deductOptions,
                    dorAddress: this.tableData.dorAddress,
                    dormitoryNo: null,
                    id: this.$route.params.id,
                    modifyTime: null,
                    remark: this.form.leaveReason,
                    storey: null,
                    totalPdeduct: this.tableData.totalPdeduct,
                    totalScore:  this.tableData.totalScore
                }
            })
            console.log(res)
            if(res.status==200){
                 this.$toast.success(res.msg)
                //  this.$router.push('/Hygiene1');
                const vm = this;
                vm.$router.push({name: 'Hygiene1'})
            }
        },
        onSelect(item){
            this.classContent=item.name;
            this.form.classId=item.id
            this.classListShare = false;
        },
        async getClassListAll(){
            const {data:res} =await this.$axios({url:this.$location.getHyDeAll});
            res.data.forEach(item=>{
                this.classList.push({
                    id:item.id,
                    name:item.deductOption
                })
            })
        },
        formatter(type, val) {
            if(type === 'year'){
                this.yyyy=val;
                return `${val}年`;
            }else if (type === 'month') {
                 this.MM=val;
                return `${val}月`;
            } else if (type === 'day') {
                 this.dd=val;
                return `${val}日`;
            }
            return val;
        },
         async select(){
            var {data:res} =await this.$axios({
                url:this.$location.getHygieneById,
                params:{
                    id:this.$route.params.id
                }
            })
           this.tableData=res.data;
           this.currentDate=res.data.checkDate
           this.classContent=res.data.deductIds
           this.form.leaveReason=res.data.remark
        }
    },
    created(){
        this.select();
         this.getClassListAll()
    }
}
</script>

<style lang="less" scoped>
 /deep/ .app-nav-bar{
        background-color: #35d299;
        .van-nav-bar__title{
            color: #fff;
        }
        .van-icon{
            color: #fff;
        }
    }
</style>